/*
 * @lc app=leetcode.cn id=888 lang=javascript
 *
 * [888] 公平的糖果棒交换
 */

// @lc code=start
/**
 * @param {number[]} aliceSizes
 * @param {number[]} bobSizes
 * @return {number[]}
 */
var fairCandySwap = function (aliceSizes, bobSizes) {
  const aliceSum = aliceSizes.reduce((p, c) => p + c);
  const bobSum = bobSizes.reduce((p, c) => p + c);
  for (let i = 0; i < aliceSizes.length; i++) {
    for (let j = 0; j < bobSizes.length; j++) {
      if (bobSizes[j] - aliceSizes[i] === (bobSum - aliceSum) / 2) {
        return [aliceSizes[i], bobSizes[j]];
      }
    }
  }
};
// @lc code=end
